import { http } from '../utils/request'

// 车辆相关API
export const vehicleAPI = {
  // 车辆信息识别（通过图片URL）
  recognizeVehicle(data) {
    return http.post('/car/vehicle/recognize/', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },

  // 提交车辆信息到数据库
  submitVehicle(data) {
    return http.post('/car/vehicle/submit/', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },

  // 获取车辆列表
  getVehicles(params = {}) {
    return http.get('/car/vehicles/', { params })
  },

  // 获取车辆详情
  getVehicleDetail(id) {
    return http.get(`/car/vehicles/${id}/`)
  },

  // 更新车辆信息
  updateVehicle(id, data) {
    return http.put(`/car/vehicles/${id}/`, data)
  },

  // 删除车辆
  deleteVehicle(id) {
    return http.delete(`/car/vehicles/${id}/`)
  }
}

// 车辆图片相关API
export const vehicleImageAPI = {
  // 车辆图片审核
  auditVehicleImage(id, data) {
    return http.post(`/car/vehicle/audit/${id}/`, data)
  },

  // 获取车辆图片列表
  getVehicleImages(vehicleId) {
    return http.get(`/car/vehicle-images/`, { vehicle_id: vehicleId }
    )
  }
}

// 车辆审核相关API
export const vehicleAuditAPI = {
  // 车辆状态审核
  auditVehicleStatus(id, data) {
    return http.post(`/car/vehicle/status/${id}/`, data)
  }
}



// 车辆违章相关API
export const vehicleViolationAPI = {
  // 获取违章记录列表
  getViolationList(params = {}) {
    return http.get('/car/vehicle-violations/', { params })
  },

  // 获取违章记录详情
  getViolationDetail(id) {
    return http.get(`/car/vehicle-violations/${id}/`)
  },

  // 创建违章记录
  createViolation(data) {
    return http.post('/car/vehicle-violations/', data)
  },

  // 更新违章记录
  updateViolation(id, data) {
    return http.put(`/car/vehicle-violations/${id}/`, data)
  },

  // 删除违章记录
  deleteViolation(id) {
    return http.delete(`/car/vehicle-violations/${id}/`)
  }
}

// 图片上传API（使用七牛云）
export const uploadAPI = {
  // 上传图片到七牛云
  uploadImage(file) {
    const formData = new FormData()
    formData.append('file', file)

    return http.post('/login/users/imgurl/', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}
